<template>
	<view class="content">
		<view class="part-list">
			<view class="part-item">
				<text>转出主机</text>
				<text>{{detail.device_name}}</text>
			</view>
			<view class="part-item">
				<text>转入主机</text>
				<text>{{detail.in}}</text>
			</view>
			<view class="part-item">
				<text>配件名</text>
				<text>{{detail.section_name}}</text>
			</view>
			<view class="part-item">
				<text>配件租金</text>
				<text>￥{{detail.rent||"0"}}/月</text>
			</view>
		</view>
	</view>
</template>

<script>
	import api from "../../../../../network/index.js"
	export default {
		data() {
			return {
				id: 0,
				detail:{
					device_name: "",
					in: "",
				}
			};
		},
		methods:{
			// 获取转出主机
			getOut(id){
				api.request({
					url: api.DEVICE_LIST,
					data:{
						id: "=,"+id
					}
				}).then(res=>{
					// console.log(res)
					if(res.data.list == "暂无数据")return
					let data = res.data.list.data[0]
					// console.log(data)
					this.detail.device_name = data.device_name
					// console.log(this.detail.out)
					// console.log(this.detail)
				}).catch(err=>{
					api.error(err)
				})
			},
			// 获取转入主机
			getIn(){
				let pages = getCurrentPages()
				let page = pages[pages.length - 2]
				// console.log(page)
				this.detail.in = page.__data__.contract.device.value
			},
			// 获取转借详情
			getDetail(id){
				api.request({
					url: api.SERVICE_SECTION_LIST,
					data:{
						order_service_id: "=,"+id
					}
				}).then(res=>{
					if(res.data.list == "暂无数据")return
					if(res.data.code == "200"){
						let data = res.data.list.data[0]
						let obj = {
							rent: data.rent,
							section_name: data.section_name,
							device_name: "",
							in: "",
						}
						this.detail = obj
						// 获得转出主机
						this.getOut(data.borrow_device_id)						
						// 获得转入主机
						this.getIn()
					}else{
						api.error(res)
					}
				}).catch(err=>api.error(err))
			}
		},
		onLoad(options) {
			this.id = options.id
			this.getDetail(options.id)
		}
	}
</script>

<style lang="scss" scoped>
.part-list{
	margin: 0 20rpx;
	padding: 20rpx;
	.part-item{
		display: flex;
		justify-content: space-between;
		padding: 20rpx;
		background-color: #FFFFFF;
		border-bottom: 1rpx solid #EEEEEE;
	}
}
</style>
